package com.sunyard.auth.service.impl;

import com.sunyard.auth.dal.dao.SmAuthUserDAO;
import com.sunyard.auth.dal.dataobject.SmAuthUserDO;
import com.sunyard.auth.dal.query.SmAuthUserQuery;
import com.sunyard.auth.service.SmAuthUserService;
import com.sunyard.auth.service.bo.SmAuthUserBO;
import com.sunyard.auth.service.convert.SmAuthUserConvert;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program auth
 * @description
 * @author raoinyx@163.com
 * @create 2020-07-18 00:23
 */
@Service
public class SmAuthUserServiceImpl implements SmAuthUserService {
    @Resource
    private SmAuthUserDAO smAuthUserDAO;

    @Override
    public List<SmAuthUserBO> findList(SmAuthUserQuery pagerCondition) {
        List<SmAuthUserDO> list = smAuthUserDAO.selectByExample(this.getExample(pagerCondition));
        return SmAuthUserConvert.toBOList(list);
    }

    private Example getExample(SmAuthUserQuery pagerCondition){
        Example example = new Example(SmAuthUserDO.class);
        Example.Criteria criteria = example.createCriteria();
        if(!ObjectUtils.isEmpty(pagerCondition.getUserId())){
            criteria.andEqualTo("userId",pagerCondition.getUserId());
        }
        if(!ObjectUtils.isEmpty(pagerCondition.getUserName())){
            criteria.andEqualTo("userName",pagerCondition.getUserName());
        }
        if(!ObjectUtils.isEmpty(pagerCondition.getPassword())){
            criteria.andEqualTo("password",pagerCondition.getPassword());
        }
        if(!ObjectUtils.isEmpty(pagerCondition.getRealName())){
            criteria.andEqualTo("realName",pagerCondition.getRealName());
        }
        if(!ObjectUtils.isEmpty(pagerCondition.getTelephone())){
            criteria.andEqualTo("telephone",pagerCondition.getTelephone());
        }
        if(!ObjectUtils.isEmpty(pagerCondition.getEmail())){
            criteria.andEqualTo("email",pagerCondition.getEmail());
        }
        if(!ObjectUtils.isEmpty(pagerCondition.getStatus())){
            criteria.andEqualTo("status",pagerCondition.getStatus());
        }
        if(!ObjectUtils.isEmpty(pagerCondition.getOrgcode())){
            criteria.andEqualTo("orgcode",pagerCondition.getOrgcode());
        }

        return example;
    }
}
